package com.ostrich.note.utils;


import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

import com.ostrich.note.R;

public class DialogUtils {

    public static void showTypeDeleteDialog(Context context,String title,DialogListener dialogListener){
        Dialog dialog = new Dialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_type_delete, null);
        TextView  tvTitle = view.findViewById(R.id.tv_title);
        tvTitle.setText("删除["+title+"]"+"分类");
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onCancelClick();
                }
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onConfirmClick();
                }
                dialog.dismiss();
            }
        });
        CheckBox checkBox = view.findViewById(R.id.cb);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(dialogListener != null){
                    dialogListener.onCheckChanged(isChecked);
                }
            }
        });

        dialog.setContentView(view);
        dialog.show();
    }


    public static void showTypeInsertDialog(Context context,DialogListener dialogListener){
        Dialog dialog = new Dialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_type_add, null);
        EditText editText = view.findViewById(R.id.et);
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onCancelClick();
                }
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = editText.getText().toString();
                if(dialogListener != null){
                    dialogListener.onConfirmClick(s);
                }
                dialog.dismiss();
            }
        });


        dialog.setContentView(view);
        dialog.show();
    }



    public static void showTypeEditDialog(Context context,String title,DialogListener dialogListener){
        Dialog dialog = new Dialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_type_add, null);
        EditText editText = view.findViewById(R.id.et);
        editText.setHint(title);
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onCancelClick();
                }
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = editText.getText().toString();
                if(dialogListener != null){
                    dialogListener.onConfirmClick(s);
                }
                dialog.dismiss();
            }
        });


        dialog.setContentView(view);
        dialog.show();
    }



    //接口回调
    public interface DialogListener{
        void onCancelClick();
        void onConfirmClick();
        void onConfirmClick(String data);
        void onCheckChanged(boolean isChecked);
    }


    public static void showNoNoteDialog(Context context,DialogListener dialogListener){
        Dialog dialog = new Dialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_no_note, null);
        view.findViewById(R.id.ri_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onCancelClick();
                }
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.ri_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialogListener != null){
                    dialogListener.onConfirmClick();
                }
                dialog.dismiss();
            }
        });


        dialog.setContentView(view);
        dialog.show();
    }




}
